public class test3 {
    public static void main(String[] args) {
        boolean[] isPrime = new boolean[20001];
        for (int i = 2; i <= 20000; i++) {
            isPrime[i] = true;
        }

        for (int factor = 2; factor * factor <= 20000; factor++) {
            if (isPrime[factor]) {
                for (int multiple = factor * factor; multiple <= 20000; multiple += factor) {
                    isPrime[multiple] = false;
                }
            }
        }

        int count = 0;
        for (int i = 2; i <= 20000; i++) {
            if (isPrime[i]) {
                System.out.print(i + " ");
                count++;
                if (count % 5 == 0) {
                    System.out.println();
                }
            }
        }
    }
}
